﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;

public partial class public_html_NewSite_CMSV2_ReviewsAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ReviewerMySql SQL = new ReviewerMySql();
        if (!IsPostBack)
        {
            TxtID.Text = Request.QueryString["id"];
            lblTitel.Text = Request.QueryString["titel"];

            OdbcDataReader Reader = SQL.ExecuteReader("SELECT * FROM V2_Writters ORDER BY Navn");
            while (Reader.Read())
            {
                DropForfatter.Items.Add(new ListItem(Reader["Navn"].ToString(), Reader["ID"].ToString()));
            }

            OdbcDataReader DisReader = SQL.ExecuteReader("SELECT * FROM V2_Distributor ORDER BY Navn");
            while (DisReader.Read())
            {
                DropDis.Items.Add(new ListItem(DisReader["Navn"].ToString(), DisReader["id"].ToString()));
            }
        }
    }

    protected void BtmSave_Click(object sender, EventArgs e)
    {
        ReviewerMySql SQL = new ReviewerMySql();

        //Forside snask
        string ID;
        string HeaderToFunc = "";
        string HeaderText = TxtHeader.Text;
        /*
        if (HeaderText.Length > 150)
        {
            HeaderToFunc = HeaderToFunc.Substring(0, 149) + "...";
        }
        else
        {
            HeaderToFunc = HeaderText;
        }
        */
        HeaderToFunc = HeaderText;
        /*
        string Forsidetitel = "";
        Forsidetitel = Regex.Replace(lblTitel.Text, "(Xbox 360)", "", RegexOptions.IgnoreCase);
        Forsidetitel = Regex.Replace(Forsidetitel, "(Nintendo Wii)", "", RegexOptions.IgnoreCase);
        Forsidetitel = Regex.Replace(Forsidetitel, "(PC)", "", RegexOptions.IgnoreCase);
        Forsidetitel = Regex.Replace(Forsidetitel, "(Playstation 3)", "", RegexOptions.IgnoreCase);
        */
        SQL.ExecuteNonQuery("INSERT INTO V2_Anmeldelse(SpilID, Header, Tekst, Karakter, Forfatter, Dis) VALUES('" + TxtID.Text + "','" + TxtHeader.Text + "','" + TxtTekst.Text + "'," + RatingKarakter.CurrentRating.ToString() + "," + DropForfatter.SelectedValue + "," + DropDis.SelectedValue + ")");
        OdbcDataReader TempReaaader = SQL.ExecuteReader("SELECT ID FROM V2_Anmeldelse ORDER BY ID DESC LIMIT 1");
        TempReaaader.Read();
        FrontPageAdmin.CreateFrontPage(lblTitel.Text, "anmeldelse", HeaderToFunc, TempReaaader[0].ToString());
        Response.Redirect("Message.aspx?MSG=Anmeldelsen blev oprettet.");
    }
}
